﻿using Microsoft.Xna.Framework;

namespace block_explorer
{
    class ChaseCamera : EntityCamera
    {
        private Vector3 mChaseOffset;

        public ChaseCamera(Vector3 offset, Vector3 chaseOffset, int viewWidth, int viewHeight, float fov, float near, float far)
            : base(offset, viewWidth, viewHeight, fov, near, far)
        {
            mChaseOffset = chaseOffset;
        }

        public override void Update(GameTime gameTime)
        {
            if (mEntity != null)
            {
                Vector3 rotatedOffset = Vector3.Transform(mChaseOffset, Quaternion.Inverse(mEntity.Orientation));
                Position = mEntity.Position + mOffset + rotatedOffset;
                Orientation = mEntity.Orientation;

                View = Matrix.CreateLookAt(Position, mEntity.Target, new Vector3(0, 1, 0));
            }
            else
                base.Update(gameTime);
        }
    }
}
